/**
 * 判断字符串是否为空--去掉左右2边的空格
 */
String.prototype.isEmpty=function(){
	var data = this.trim();
	if(null == data || "" == data){
		return true;
	}
	return false;
}
function isEmpty(str){
	if(str == null || "" == str || "undefined" == str){
		return true;
	} 
	return false;
}

/**
 * 替换
 * @param s1
 * @param s2
 * @return
 */
String.prototype.replaceAll=function (s1,s2){ 
	return this.split(s1).join(s2);
}
/**
 * 是否以xxx开头
 */
String.prototype.StartWith=function(s){
	  if(s==null||s==""||this.length==0||s.length>this.length)
	   return false;
	  if(this.substr(0,s.length)==s)
	     return true;
	  else
	     return false;
	  return true;
}

/**
 * 删除左右2边的空格
 */
String.prototype.trim=function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
 }


/**
 * 删除左边的空格
 */
String.prototype.trimLeft=function(){
    return this.replace(/(^\s*)/g,"");
 }

/**
 * 删除右边的空格
 */
String.prototype.trimRight=function(){
    return this.replace(/(\s*$)/g,"");
 }


/**设置指定大小*/
$.fn.setWidthSize = function(obj){

	 var width=obj.width,//width
	 	height=obj.height,//height
	 	isScaleByWidth = obj.isScaleByWidth == null ? false:true,//是否以width为基准---比例
		reduceWidth=obj.reduceWidth,//减少width
		reduceHeight=obj.reduceHeight,//减少height
		isScale = obj.isScale == null ? true:false,//是否是按比例，
		isEqual = obj.isEqual == null ? false:true,//是否相等--如相等--直接以width为基准
		marginRight = obj.marginRight,//是否向右间距--值为px
		marginLeft = obj.marginLeft,
		marginBottom = obj.marginBottom,
		marginRight_scale = obj.marginRight_scale,
		marginBottom_scale = obj.marginBottom_scale,
		marginLeft_scale = obj.marginLeft_scale,
		widthAndHeightScale = obj.widthAndHeightScale == null ? false:obj.widthAndHeightScale;//长于宽的比例--以width为基准
		//是否向左间距--值为px
	//默认按比例
	 if(isScale){
		 if(width){
			 var winWidth = $(window).width();
			 width = winWidth*width;
		 }
		 if(height){
			 
			 if(isScaleByWidth){
				 var winWidth = $(window).width();
				 height = winWidth*height;
			 } else{
				 var winHeight = $(window).height();	
				 height = winHeight*height;
			 }
		 }
	 }
	 
	 //长宽比例
	 if(widthAndHeightScale){
		 height = width/widthAndHeightScale;
	 }
	 if(reduceWidth){//需要进行减的长度
		 width -= reduceWidth;
	 }
	 
	 if(reduceHeight){//需要进行减的高度
		 height -= reduceHeight;
	 }
	 
	 if(isEqual){//相等以width为基准
		 height = width;	
	 }
	 //向右间距
	 if(marginRight){
		 $(this).css("marginRight",marginRight+"px");
	 }
	//向左间距
	 if(marginLeft){
		 $(this).css("marginLeft",marginLeft+"px");
	 }
	//向左间距
	 if(marginBottom){
		 $(this).css("marginBottom",marginBottom+"px");
	 }
	 
	 //向右间距
	 if(marginRight_scale){
		 $(this).css("marginRight",marginRight_scale+"%");
	 }
	//向左间距
	 if(marginLeft_scale){
		 $(this).css("marginLeft",marginLeft_scale+"%");
	 }
	//向下间距
	 if(marginBottom_scale){
		 $(this).css("marginBottom",marginBottom_scale+"px");
	 }
	
	 if(width){
		 $(this).width(width);
	 }
	 if(height){
		 $(this).height(height);
	 }
}

//ie7,ie7等版本
/**设置指定大小*/
function the_setWidthSize(setBean,obj){

	 var width=obj.width,//width
	 	height=obj.height,//height
	 	isScaleByWidth = obj.isScaleByWidth == null ? false:true,//是否以width为基准---比例
		reduceWidth=obj.reduceWidth,//减少width
		reduceHeight=obj.reduceHeight,//减少height
		isScale = obj.isScale == null ? true:false,//是否是按比例，
		isEqual = obj.isEqual == null ? false:true,//是否相等--如相等--直接以width为基准
		marginRight = obj.marginRight,//是否向右间距--值为px
		marginLeft = obj.marginLeft,
		marginBottom = obj.marginBottom,
		marginRight_scale = obj.marginRight_scale,
		marginBottom_scale = obj.marginBottom_scale,
		marginLeft_scale = obj.marginLeft_scale,
		widthAndHeightScale = obj.widthAndHeightScale == null ? false:obj.widthAndHeightScale;//长于宽的比例--以width为基准
		//是否向左间距--值为px
	//默认按比例
	 if(isScale){
		 if(width){
			 var winWidth = $(document).width();
			 width = winWidth*width;
		 }
		 if(height){
			 
			 if(isScaleByWidth){
				 var winWidth = $(document).width();
				 height = winWidth*height;
			 } else{
				 var winHeight = $(document).height();	
				 height = winHeight*height;
			 }
		 }
	 }
	 
	 //长宽比例
	 if(widthAndHeightScale){
		 height = width/widthAndHeightScale;
	 }
	 if(reduceWidth){//需要进行减的长度
		 width -= reduceWidth;
	 }
	 
	 if(reduceHeight){//需要进行减的高度
		 height -= reduceHeight;
	 }
	 
	 if(isEqual){//相等以width为基准
		 height = width;	
	 }
	 //向右间距
	 if(marginRight){
		 $(setBean).css("paddingRight",marginRight+"px");
	 }
	//向左间距
	 if(marginLeft){
		 $(setBean).css("paddingLeft",marginLeft+"px");
	 }
	//向xia间距
	 if(marginBottom){
		 $(setBean).css("marginBottom",marginBottom+"px");
	 }
	 
	 //向右间距
	 if(marginRight_scale){
		 $(setBean).css("paddingRight",marginRight_scale+"%");
	 }
	//向左间距
	 if(marginLeft_scale){
		 $(setBean).css("paddingLeft",marginLeft_scale+"%");
	 }
	//向下间距
	 if(marginBottom_scale){
		 $(setBean).css("paddingBottom",marginBottom_scale+"px");
	 }
	
	 if(width){
		 $(setBean).width(width);
	 }
	 if(height){
		 $(setBean).height(height);
	 }
}

(function($){
	 /*******************************************************************************
	  * ontap事件--多个
	  */
    $.fn.ontapMoreSame = function(obj){
    	if(obj == null){
    		obj = {};
    	}
    	if(obj.btn_show){
    		var showCss = obj.showCss;
    		var showFunc = obj.showFunc;
    		$(this).die("touchstart").live("touchstart",function(event){
    			if(showCss){
    				$(this).css(showCss);
    			}
    			if(showFunc){
    				showFunc();
    			}
        	});
    		$(this).die("touchend").live("touchend",function(event){
    			var endCss = obj.endCss;
    			var endFunc = obj.endFunc;
    			if(endCss){
    				$(this).css(endCss);
    			}
    			if(endFunc){
    				endFunc();
    			}
        	});
    	}
    	$(this).die("tap").live("tap",function(event){
    		event.preventDefault();
    		var endObj = $(this);
    		//setTimeout(function(){
    			eval(endObj.attr("ontap"));
    		//},200);
    	});
    }
})(jQuery);



/**
 * 获取总页数
 * 
 * @param total
 * @param rows
 * @return
 */
function getPageSum(total,rows){
	if(total == 0){
		return 1;
	}
	if(total % rows != 0){
		return parseInt(total / rows + 1);
	}
	if(total % rows == 0){
		return parseInt(total / rows);
	}
}
/**
 * map数据初始化
 * @param data
 * @param page
 * @return
 */
function initMapByData(obj){
	var data = obj.data,
		page = obj.page,  //page对象--在没有sf的情况下，
		idName = obj.idName,//  id名称
		idNameTree=obj.idNameTree,//id名称有下级
		needAllMap = obj.needAllMap, //是否需要allMap集合
		pageSum = obj.pageSum, //在有sf的情况下，定义page对象时需要用的每页显示数量
		sf = obj.sf; //有sf的情况下

	var rows = data.result.rows;
	if(page == null){
		page ={
			pageNo:1,
			pageSum:1,
			pageRows:pageSum,
			pageMap:null,
			allMap:null
		};	
	}
	if(page.pageNo == 1){
		page.pageSum = getPageSum(data.result.total,page.pageRows);
	}
	var len = rows.length;
	var tempMap = new Map();
	for(var i = 0;i< len;i++){
		tempMap.put(tempMap.size()+1,rows[i]);
		if(needAllMap){
			if(page.allMap == null){
				page.allMap = new Map();
			}
			if(idName){
				if(!isEmpty(idNameTree)){//photoes[0]
					page.allMap.put(eval('rows['+i+'].'+idNameTree+'.'+idName),rows[i]);
				} else{
					page.allMap.put(eval('rows['+i+'].'+idName),rows[i]);
				}
			} else{
				page.allMap.put(page.allMap.size()+1,rows[i]);
			}
		}
	}
	if(page.pageMap == null){
		page.pageMap = new Map();
	}
	page.pageMap.put(page.pageMap.size()+1, tempMap);
	page.nowMap = tempMap;
	if(sf){
		if(sf.sfMap == null){
			sf.sfMap = new Map();
		}
		sf.sfMap.put(sf.sfIndex,page);
	}
	
	return page;
}



